import { resolve } from "url"
import * as RouteApi from "@/api/route/route.js" 
import Socket from "@/utils/socket/socket.js"
import config from "@/core/config/index.js"
import user from "./user.js"

export default {
    namespaced: true, 
	state:{
		socket:null
	},
	actions:{
		openSocket({state}){
			console.log("socket.js openSocket")
			state.socket = Socket.Instance
			const userId = user.state.userId
			if(state.socket.ws !== null){
				state.socket.destroyed()
			}
			state.socket.init(config.get('wsUrl')+userId)
			
		},
		closeSocket({state}){
			if(state.socket !== null){
				state.socket.close()
			}
		},
		destroy({state}){
			if(state.socket !== null){
				state.socket.destroyed()
			}
		},
		
		regHeartBeatCallback({state},value){
			state.socket.regHeartBeatCallback(value)
		},
		
		startHeartBeatFn({state},value){
			console.log("----startHeartBeat---")
			state.socket.startHeartBeat(value)
		},
		closeHeartBeatFn({state}){
			state.socket.closeHeartBeatData()
		}
		
	},
	
}